package com.hb.medical_research_system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hb.medical_research_system.common.Results;
import com.hb.medical_research_system.entity.Article;
import com.hb.medical_research_system.entity.Search;
import com.hb.medical_research_system.service.ArticleService;
import com.hb.medical_research_system.service.SearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "搜索记录")
@Slf4j
@RestController
@RequestMapping("/search")
public class SearchController {

    private final SearchService searchService;

    @Autowired
    public SearchController(SearchService searchServicer){
       this.searchService = searchServicer;
    }

//    @Autowired
//    private SearchService searchService;

    @ApiOperation("添加搜索记录结果")
    @PostMapping("/add")
    public Results add(@RequestBody Search search){
        searchService.add(search);
        return Results.info(Results.SUCCESS,"新增记录成功");
    }

    @ApiOperation("根据用户id查询记录")
    @GetMapping("/search1")
    public Results findSearch(@RequestParam Long userId){
        return searchService.findSearchByUserId(userId);
    }

    @ApiOperation("根据用户id查询记录(分页)")
    @GetMapping("/search2")
    public Results searchByTitle2(Long id, int page, int pageSize){
        Page<Search> articlePage = searchService.findByUserId(id, page, pageSize);
        return Results.data(Results.SUCCESS,articlePage,"查询成功");
    }

}
